package com.eastjet.equipment.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastjet.equipment.service.InspectionDetailsService;
import com.eastjet.equipment.service.SelectTypeService;
import com.eastjet.maintenance.domain.DeviceInspectiontask;
import com.eastjet.maintenance.domain.InboundDetails;
import com.eastjet.maintenance.domain.InspectionDetails;
import com.eastjet.maintenance.domain.SelectType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("details")
public class InspectionDetailsController {

    @Autowired
    private InspectionDetailsService inspectionDetailsService;
    @Autowired
    private SelectTypeService selectTypeService;
    @GetMapping("/InsList")
    public Page<InspectionDetails> getSupplierList(@RequestParam(defaultValue = "1") int page,
                                                   @RequestParam(defaultValue = "2") int size,
                                                   @RequestParam(defaultValue ="") String deviceCode
    ) {
        System.out.println("condition:" + deviceCode);
        System.out.println("page:"+page);
        return  inspectionDetailsService.selectIns(page, size,deviceCode);
    }



    @GetMapping("/selectDes")
    public List<InspectionDetails> query(@RequestParam("")String code){
        System.out.println("code:"+code);
        return  inspectionDetailsService.selectDe(code);
    }

    @GetMapping("selectList")
    public List<SelectType> getSelectType(@RequestParam("")String code){
        QueryWrapper qw=new QueryWrapper();
        qw.eq("code",code);
        return selectTypeService.list(qw);
    }

    @RequestMapping("/updateDetailState")
    public String updateTask(@RequestBody Map<String,Object> map){
        InspectionDetails details= new InspectionDetails();
        details.setIsJudge((String) map.get("options"));
        details.setCode((String) map.get("code"));
        details.setProject((String) map.get("project"));
        details.setCodeType((String) map.get("codeType"));
        System.out.println("details:"+map);
       int result=Integer.valueOf((Integer) map.get("isResult"));
        if(result==1){
            details.setState(1);
        }else{
            details.setState(0);
        }

        return  inspectionDetailsService.updateDetailState(details);
    }

    @GetMapping("/selectInspection")
    public List<InspectionDetails> selectInspection(@RequestParam("")String code, @RequestParam("")String condition,@RequestParam("")String content,@RequestParam("")String type){
        System.out.println("code:"+code);
        System.out.println("condition:"+condition);
        System.out.println("type:"+type);
        System.out.println("content:"+content);
        return inspectionDetailsService.selectInspection(code,condition,type,content);
    }


}
